import { BadRequestException } from '@nestjs/common';
import * as argon2 from 'argon2';
// import * as crypto from 'crypto';

// 在服务中
export async function hashPassword(password: string) {
  return await argon2.hash(password);
}

// 验证密码
export async function comparePassword(hash: string, password: string) {
  let result = false;
  try {
    result = await argon2.verify(hash, password);
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
  } catch (err) {
    throw new BadRequestException('密码格式有误');
  }
  return result;
}
